/*
 * Application.java
 *
 * Created on November 8, 2006, 8:26 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.umn.cs5115.scheduler.framework;

import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;


/**
 * This class is intended to be used to be used for things that need to be
 * accessible application-wide.  It should eventually replace some of the
 * functionality that's now in DocumentController, but that doesn't really 
 * belong there.
 * @author grant
 */
public class Application
{
    /** Font to use for system labels. */
    private static Font systemLabelFont;
    /** The OS that we've found we're running on */
    private static OS theOS;
    /** Whether or not theOS is initialized. */
    private static boolean osInitialized;
    
    /** 
     * Get the font used for system labels.
     * @return The font used on labels.
     */
    public static Font getSystemLabelFont()
    {
        if (systemLabelFont == null)
        {
            Shell window = DocumentController.getSharedDocumentController().getAnyShell();
            
            // create a temporary window if there isn't a shell available for use.
            Shell temporaryWindow = null;
            if (window == null)
            {
                temporaryWindow = new Shell(DocumentController.getSharedDocumentController().getDisplay());
                window = temporaryWindow;
            }
            Label label = new Label(window, 0);
            systemLabelFont = label.getFont();
            label.dispose();
            if (temporaryWindow != null)
                temporaryWindow.dispose();
        }
        return systemLabelFont;
    }
    
    /**
     * Get the OS that the program is running on.
     * @return An OS constant.  Right now, it returns only MAC_OS_X or UNKNOWN.
     * People who know how to can add other constants.
     */
    public static OS getOS()
    {
        if (!osInitialized)
        {
            String osname = System.getProperty("os.name").toLowerCase();
            if (osname.startsWith("mac os x"))
                theOS = OS.MAC_OS_X;
            else
                theOS = OS.UNKNOWN;
            osInitialized = true;
        }
        return theOS;
    }
    
    /**
     * Constants for determining what OS the application is running on.
     * @see #getOS()
     */
    public static enum OS
    {
        MAC_OS_X,
        LINUX,
        WINDOWS,
        UNKNOWN
    }
}
